﻿using UnityEngine;
using System.Collections;

public class HighscoreFlashing : MonoBehaviour 
{
    private GUIText highText;
    private PersistentManagerScript manager;
    private float red = 1.0f;
    private float redDirection = 1;
    private float green = 1.0f;
    private float greenDirection = 1;
    private float blue = 0.0f;
    private float blueDirection = 1;

	void Start () 
    {
        manager = GameObject.Find("PersistentManager").GetComponent<PersistentManagerScript>();
        highText = gameObject.GetComponent<GUIText>();
        highText.enabled = true;
	}
	
	void Update () 
    {
        if (manager.GetRecentScore() == manager.GetMaxScore())
        {
            highText.enabled = true;

            red += Time.deltaTime * redDirection;
            if (red < 0.0f || red > 1.0f)
            {
                redDirection *= -1;
                red = Mathf.Clamp(red, 0, 1);
            }

            green += Time.deltaTime * 1.5f * greenDirection;
            if (green < 0.0f || green > 1.0f)
            {
                greenDirection *= -1;
                green = Mathf.Clamp(green, 0, 1);
            }

            blue += Time.deltaTime * 2 * blueDirection;
            if (blue < 0.0f || blue > 1.0f)
            {
                blueDirection *= -1;
                blue = Mathf.Clamp(blue, 0, 1);
            }

            highText.color = new Color(red, green, blue);

        }
        else
        {
            highText.enabled = false;
        }
	}
}
